package com.example.demo.controller;

import com.example.demo.POJO.responseMessage;
import com.example.demo.mapper.loginMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//rest控制器，用于接收来自浏览器的请求
@RestController
@RequestMapping("/api")
public class loginController {

    //查找ioc容器，当发现mybatis接口时，获取mybatis接口的实现子类
    @Autowired
    private loginMapper lm;

    //接收get请求，请求路径为项目根路径+/login      项目根路径为/，所以请求路径为/login   123
    @GetMapping("/isLogin")
    //@RequestParam表示获取请求包中的对应属性
    responseMessage<String> login(@RequestParam("username") String username , @RequestParam("password") String password){
        String name = lm.isLogin(username , password);
        responseMessage<String> rm = new responseMessage<String>();
        rm.setCode(200);
        rm.setMessage("收到请求");
        if(name == ""){
            rm.setData("error");
        }else{
            rm.setData("success");
        }
        return rm;
    }

}
